package com.glodon.paas.account.security.cas;

import org.jasig.cas.authentication.principal.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Resolve the <code>UsernamePasswordCredentials</code> to <code>Principal</code>
 *
 * @author Don Li
 */
public class UseridPasswordCredentialsToPrincipalResolver implements CredentialsToPrincipalResolver {
    private static final Logger LOGGER = LoggerFactory.getLogger(UseridPasswordCredentialsToPrincipalResolver.class);

    @Override
    public Principal resolvePrincipal(Credentials credentials) {
        UsernamePasswordCredentials c = (UsernamePasswordCredentials) credentials;
        LOGGER.debug("Retrieve principal with userid : {}", c.getUsername());
        return new SimplePrincipal(c.getUsername()); // more attributes maybe added here.
    }

    @Override
    public boolean supports(Credentials credentials) {
        return credentials != null && UsernamePasswordCredentials.class.isAssignableFrom(credentials.getClass());
    }
}
